﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;
using Model;

namespace 超市收银台
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F2)
            {
                textBox1.Focus();
            }
        }
        private void Search()
        {
            
            textBox1.Text = "dfdfd";
        }
        private void txtSearch_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F5)
            {
                Search();
            }
            else if (e.KeyCode == Keys.Enter)
            {
                yyyy();
            }
        }

        private void txtSearch_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnjiesuan_Click(object sender, EventArgs e)
        {
            Search();
        }

        private List<BuyGoods> buygoods = new List<BuyGoods>();
        private void btnSearch_Click(object sender, EventArgs e)
        {
            yyyy();

        }
        public void yyyy()
        {
            BuyGoods bg = new BuyGoods();
            string shuju = textBox1.Text.ToString();
            GoodsService gs = new GoodsService();
            string j = chuansongshuju();
            List<GoodsInfo> list = gs.SelectGoods(j);
            if (list.Count == 1)
            {

                dataGridView1.DataSource = gs.SelectGoods(j);
            }
            else if(list.Count==0)
            {
                MessageBox.Show("查询失败");
            }
            else  
            {
                SelectGoodsForm2 f = new SelectGoodsForm2(list);
                f.ShowDialog();
                try
                {
                    bg.GoodsCode = f.goods.GoodsCode;
                    bg.GoodsName = f.goods.GoodsName;
                    bg.SalePrice = f.goods.SalePrice;
                    bg.Count = 2;
                    //bg.Xiaoji = f.goods.SalePrice * bg.Count;
                    buygoods.Add(bg);
                    dataGridView1.DataSource = new BindingList<BuyGoods>(buygoods);
                }
                catch (Exception)
                {


                }
            }
            
        }
            
            
        

        private void Form1_Load(object sender, EventArgs e)
        {
            dataGridView1.AutoGenerateColumns = false;
        }
        public string  chuansongshuju()
        {
            
            string shuju = textBox1.Text.ToString();
            return shuju;
            
        }
    }
}
